package cn.doctorpda.conference.presenter;

import cn.doctorpda.conference.bean.Msg;
import cn.doctorpda.conference.config.NetConfig;
import cn.doctorpda.conference.model.GetCodeModel;
import cn.doctorpda.conference.model.IPostModel;
import cn.doctorpda.conference.okhttp.callback.StringCallback;
import cn.doctorpda.conference.utils.GsonUtil;
import cn.doctorpda.conference.view.callbackview.IMsgView;
import okhttp3.Call;

/**
 * Created by huangjinlong on 2016/5/20.
 */
public class GetCodePresenter {
    private IMsgView baseView;
    private IPostModel baseModel;

    public GetCodePresenter(IMsgView baseView){
        this.baseView = baseView;
        baseModel = new GetCodeModel();
    }

    public void getCode(String mobile){
        baseModel.postNetWorkStringData(NetConfig.GET_CODE, new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {
                baseView.setError(call, e);
            }

            @Override
            public void onResponse(String response) {
                try {
                    Msg msg = GsonUtil.fromJson(response, Msg.class);
                    baseView.setResult(msg);
                } catch (Exception e){
                    e.printStackTrace();
                }

            }
        }, mobile, "con");
    }
}
